//
//  BaseTableViewController.swift
//  SinaWeiBo20
//
//  Created by tarena on 16/3/18.
//  Copyright © 2016年 tarena. All rights reserved.
//

import UIKit
import AFNetworking




class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {
    
    var userLogin = UserAccountViewModel().userLogin

    var visitorLoginView : VisitorLoginView?
    
    
    //VisitorLoginViewDelegate 方法
    func visitorWillLogin() {
        presentViewController(UINavigationController(rootViewController: OAuthViewController()), animated: true, completion: nil)
        
    }
    func visitorWillRegister() {
        print("come on")
    }
    
    
    //loadView 是苹果专门为手写嗲吗 准备的 等效于 sb／xib
    //一旦实现这个方法 xib／ sb 就自动失效
    //自动检测 view 是否为空 如果为空 会自动调用 loadView 方法
    override func loadView() {
         userLogin ? super.loadView() : loadVisitorView()
    }
    
    private func loadVisitorView() {
        
        //设置当前视图
        visitorLoginView = VisitorLoginView()
        visitorLoginView?.visitorDelegate = self
        view = visitorLoginView
        
        //设置导航按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorWillLogin")
        
    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }


}
